<!--集包记录-->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />
    <ex_super_table_page v-bind="option" ref="SuperTablePage" :autoLoad="false"
      @selection-change="list => selection = list">

    </ex_super_table_page>

    <package_collection_detail ref="package_collection_detail" />

    <print_outbound_pallet ref="print_outbound_pallet" />

    <common_print_dialog ref="print_package_collection_detail" :templateVisiable="false"
      :title="$tt('label_print_any', { type: 'label_package_collection_detail', i18n: true })" :tableModel="[
      { key: 'boxNo', label: 'label_package_collection_no', 'min-width': 140, },
      {
        key: 'customerNames', label: 'label_customer_name', 'width': 140, 'show-overflow-tooltip': true,
        formatter: (r, c, v, i) => {
          const codeList = r.customerCodes ? _.uniq(r.customerCodes.split(',')) : []
          const nameList = r.customerNames ? _.uniq(r.customerNames.split(',')) : []
          if (codeList.length > 0 && codeList.length == nameList.length) {
            if (codeList.length == 1) {
              return this.$formatNameCode(nameList[0], codeList[0])
            } else {
              return this.$tt('label_mixed_customer')
            }
          }
        }
      },
    ]" printUrl="/wms-api/outbound/OutboundBoxRpc/printPdf.json" :printHandler='(data, list) => {
      return {
        printList: list.map(it => {
          return {
            id: it.id,
            clientName: data.clientName,
            printerName: data.printerName,
            printCount: data.printNumSum,
          }
        })
      }
    }' previewUrl="/wms-api/outbound/OutboundBoxRpc/downloadPdf.json" :previewHandler='(data, row) => {
      return { boxId: row.id }
    }' />

  </div>
</template>

<script>
import print_outbound_pallet from '@/component/print/print_outbound_pallet.vue'

import business_function from "@/common/business_function"

import package_collection_detail from './dialog/package_collection_detail.vue';
import superTablePageFunction from '@/mixin/super-table-page-function';
import page_table_model_manage from '@/mixin/page_table_model_manage';
let emitKey = 'outbound>package_collection_record'
import emitOnFunction from '@/mixin/emit-on-function';
import common_print_dialog from '@/component/print/common_print_dialog.vue';

import router_params from '@/mixin/router_params';
export default {
  title: "title_package_collection_record",
  mixins: [superTablePageFunction, router_params, emitOnFunction(emitKey), page_table_model_manage],
  components: { package_collection_detail, print_outbound_pallet, common_print_dialog, },
  data() {
    return {
      selection: [],
      isConfirm_routeParamsChange: false,
      option: {
        search: {
          model: [
            { label: "label_package_collection_no", key: "boxNos", placeholder: 'tip_input_can_comma_separated' },
            { label: "label_track_or_package_code", key: "packageNo", },
            { label: "label_tms_common_carrier", key: "supplierName", },
            { label: "label_is_checkout", key: "checkoutFlag", type: 'select', enum: 'YesOrNoEnum' },
            { label: 'label_status', key: 'boxStatus', type: 'select', enum: 'WmsOutboundBoxStatusEnum' },
            { label: "label_sku", key: "skuId", type: "sku_selec_input" },
            {
              label: "label_create_time", key: 'startDate', type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const limitKey = 'endDate'; const value = data[item.key]; const limitValue = data[limitKey];
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_start_time"
                  attrs={{ type: 'datetime' }} pickerOptions={{ disabledDate: date => { return limitValue ? (limitValue < date.getTime()) : false } }}
                />)
              }
            },
            {
              label: "~", key: 'endDate', type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const limitKey = 'startDate'; const value = data[item.key]; const limitValue = data[limitKey];
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_end_time"
                  attrs={{ type: 'datetime', 'default-time': '23:59:59' }} pickerOptions={{ disabledDate: date => { return limitValue ? (limitValue > date.getTime()) : false } }}
                />)
              }
            },
          ],

        },
        actionExtra: [
          {
            label: 'label_export_collect_package', click: this.exportBigPackage
          },
          {
            label: 'label_export_collect_package_specification', click: this.exportBigPackageSpec
          },
          {
            label: { _key: 'label_print_any', type: 'label_package_collection_detail', i18n: true },
            click: () => {
              if (_.isEmpty(this.selection)) return this.$message.error(this.$tt('tip_please_select_order'))
              this.$refs.print_package_collection_detail.show(this.selection)
            }
          },
        ],
        table: {
          url: "/wms-api/outbound/OutboundBoxRpc/selectListPage.json",
          model: this.init_table_model(),
        }
      },
    };
  },

  mounted() {
    if (this.$refs['SuperTablePage']) {
      this.$refs['SuperTablePage'].setSearchData(Object.assign({}, this.$refs['SuperTablePage'].getSearchData(), this.$route.query))
    }
  },

  methods: {

    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, keyGroup: 'label_table_operate' },
        { key: 'boxNo', label: 'label_package_collection_no', 'min-width': 140, },
        // { key: 'bizType', label: 'label_business_type', 'width': 120, formatter: (r, c, v) => this.$enumShow(v, "BizTypeEnum") },

        {
          key: 'customerNames', label: 'label_customer_name', 'width': 140, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => {
            const codeList = r.customerCodes ? _.uniq(r.customerCodes.split(',')) : []
            const nameList = r.customerNames ? _.uniq(r.customerNames.split(',')) : []
            if (codeList.length > 0 && codeList.length == nameList.length) {
              if (codeList.length == 1) {
                return this.$formatNameCode(nameList[0], codeList[0])
              } else {
                return this.$tt("label_mixed_customer")
              }
            }
          }
        },
        // { key: 'packageNo', label: 'label_track_or_package_code', 'min-width': 120, 'show-overflow-tooltip': true, },
        { key: 'totalWeight', label: 'label_package_collection_weight', 'min-width': 100, 'show-overflow-tooltip': true, },
        { key: 'totalVolume', label: 'label_package_collection_volume', 'min-width': 100, 'show-overflow-tooltip': true, },
        { key: 'packageCount', label: 'label_package_collection_count', 'min-width': 80, 'show-overflow-tooltip': true, },
        { key: 'containerCode', label: 'label_container_code', 'min-width': 120, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$formatNameCode(v, r.containerType) },
        // { key: 'containerType', label: 'label_container_type', 'min-width': 100, 'show-overflow-tooltip': true, },
        { key: 'materialName', label: 'label_pack_material', 'min-width': 100, 'show-overflow-tooltip': true, },
        {
          label: "label_is_checkout", key: "checkoutFlag", 'width': 100, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v ? v : 'N', "YesOrNoEnum")
        },
        {
          key: 'totalOrderCount', label: 'label_order_count', 'width': 100, 'show-overflow-tooltip': true,
        },
        {
          key: 'totalPieceCount', label: 'label_sku_count', 'width': 100, 'show-overflow-tooltip': true,
        },
        {
          key: 'supplierName', label: 'label_final_supplier', 'width': 100, 'show-overflow-tooltip': true,
          // formatter: (r, c, v, i) => this.$formatNameCode(v, r.supplierCode)
        },
        {
          key: 'status', label: 'label_status', 'width': 100, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "WmsOutboundBoxStatusEnum")
        },
        { key: 'creator', label: 'label_operate_user', 'min-width': 100, 'show-overflow-tooltip': true, },
        { key: 'gmtCreate', label: 'label_create_time', formatter: (r, c, v, i) => this.$dateFormat(v) },
        {
          type: 'operate', width: 200, fixed: 'right', operate: [
            {
              label: 'label_resume', if: (row) => row.status == 'PROCESSING',
              click: (row) => {
                this.$router.push({ name: '/page/wms/overseas/outbound/package_collection', params: { 'boardNo': row.boxNo } })
              },
            },
            {
              label: 'label_cancel', if: (row) => row.status == 'PROCESSING', type: "confirm-button",
              url: '/wms-api/outbound/OutboundBoxRpc/cancelWmsOutboundBox.json',
              message: 'text_confirm_sure_cancel',
              buttonClass: "button_text_danger", confirmButtonType: 'danger',
              params: (row) => { return { "boxId": row["id"] } }, done: ['reload', 'tip']
            },
            {
              type: 'more',
              items: [
                {
                  label: 'label_view_detail', click: (row) => {
                    this.$refs.package_collection_detail.show(row.boxNo)
                  },
                },
                {
                  label: 'label_print',
                  click: (row) => this.$refs.print_outbound_pallet.show([{ ...row, boardNo: row.boxNo }], { single: true, }),
                },


              ]
            }
          ]
        }
      ]
    },
    init_data_default(into_params) {
      if (this.$refs['SuperTablePage']) {
        this.$refs['SuperTablePage'].setSearchData(Object.assign({}, this.$refs['SuperTablePage'].getSearchData(), into_params))
        this.$nextTick(() => {
          this.$refs['SuperTablePage'].loadDataForSearch()
        })
      }

    },
    exportBigPackage() {
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: this.$refs.SuperTablePage.getSearchData(),
        model: this.option.search.model,
        callback: (selection, data) => {
          let idList = this.selection.map(item => item.id)
          let params = { ...data, boxNos: data.boxNos ? data.boxNos.split(',') : [], idList: idList.length > 0 ? idList : null }
          this.$functionCommon({
            url: "/wms-api/outbound/OutboundBoxRpc/exportBoxExcel.json",
            data: params,
            system: "wms",
          })
        }
      })

    },
    exportBigPackageSpec() {
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: this.$refs.SuperTablePage.getSearchData(),
        model: this.option.search.model,
        callback: (selection, data) => {
          let idList = this.selection.map(item => item.id)
          let params = { ...data, boxNos: data.boxNos ? data.boxNos.split(',') : [], idList: idList.length > 0 ? idList : null }
          this.$functionCommon({
            url: "/wms-api/outbound/OutboundBoxRpc/exportBoxDetailExcel.json",
            data: params, system: "wms",
          })
        }
      })

    },
  }
};

</script>
<style></style>
